<?php
define('DEFAULTPATH', __FILE__ ? getdirname(__FILE__).'/': './');
define('HOMEPATH', DEFAULTPATH);
$basePath = __FILE__ ? getdirname(__FILE__): '';
$baseurl = "http://".$_SERVER['HTTP_HOST']."/".getHomePath($basePath)."/";
require_once(HOMEPATH.'libs/smarty/Smarty.class.php');
require_once(HOMEPATH.'includes/sqlconfig.php');
require_once(HOMEPATH.'includes/db.php');

class App_Config extends Smarty {
	function App_Config($theme) {
		$this->Smarty();
		
		$this->template_dir = HOMEPATH.'templates/'.$theme."/";
		$this->compile_dir = HOMEPATH.'templates_c/';
		$this->config_dir = HOMEPATH.'configs/';
		$this->cache_dir = HOMEPATH.'cache/';
		
		$this->caching = false;
		$this->debugging = true;
	}
}

$db = new dbConfig($dbhost, $dbuser, $dbpw, $dbname);

$theme = "default";

$smarty = new App_Config($theme);
$smarty->assign('baseurl',$baseurl);
$smarty->assign('theme',$theme);

function getdirname($path) {
	if(strpos($path, '\\') !== false) {
		return substr($path, 0, strrpos($path, '\\'));
	} else if (strpos($path, '/') !== false) {
		return substr($path, 0, strrpos($path, '/'));
	} else {
		return '/';
	}
}

function getHomePath($path) {
	if(strpos($path, '\\') !== false) {
		return substr($path, strripos($path, '\\')+1);
	} else if (strpos($path, '/') !== false) {
		return substr($path, strripos($path, '/')+1);
	} else {
		return '/';
	}
}
?>